package trusteva

import (
	"cybertwin/pb/trustEva"
	"cybertwin/utils/configtools"

	"github.com/sirupsen/logrus"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

// TrustEvaConn 与信任引擎做gRPC交互的客户端
var TrustEvaConn *grpc.ClientConn
var TrustEvaClient trustEva.TrustEvaluationClient

func init() {
	addr := configtools.GlobalConfiguration.GetString("trustEngine.addr")
	if len(addr) == 0 {
		logrus.Warnf("[trusteva]-[init]-无法获配置中的trustEngine.addr字段")
		return
	}
	var err error
	TrustEvaConn, err = grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		logrus.Errorf("[trusteva]-[init]-连接信任引擎失败, err: %s", err)
		return
	}
	TrustEvaClient = trustEva.NewTrustEvaluationClient(TrustEvaConn)
}
